package ch4;

public class Company {
	String name;
	String phone;
	String address;

	public Company() {
	}

	public Company(String name, String phone, String address) {
		super();
		this.name = name;
		this.phone = phone;
		this.address = address;
	}

	Employee[] employee = new Employee[100];

	public void showCompanyinfo() {
		System.out.println("公司名称：" + name + "\n公司电话：" + phone + "\n公司地址：" + address);
		for (int i = 0; i < employee.length; i++) {
			if (employee[i] != null) {
				// System.out.println(employee[i].name+",");
				employee[i].showinfo();
				System.out.println("***************************");
			}
		}
	}

	// 雇佣新人
	public boolean hire(Employee e) {
		for (int i = 0; i < employee.length; i++) {
			if (employee[i] == null) {
				employee[i] = e;
				return true;
			}
		}
		return false;
	}

	// 根据工号 开除员工
	public boolean fire(String num) {
		for (int i = 0; i < employee.length; i++) {
			if (employee[i] != null && employee[i].number.equals(num)) {
				for (int j = i + 1; j < employee.length; j++) {
					employee[j - 1] = employee[j];
				}
				employee[employee.length - 1] = null;
				return true;
			}
		}
		return false;
	}

	public int getEmploys() {
		int c = 0;
		for (int i = 0; i < employee.length; i++) {
			if (employee[i] == null)
				break;
			c++;
		}
		return c;
	}

	// 找到薪水最高的人
	public Employee findTopSalary() {
		if (employee[0] == null)// 没有空档的情况下
			return null;
		int c = 0;
		double max = employee[0].salary;
		for (int i = 0; i < employee.length; i++) {
			if (employee[i] != null && max < employee[i].salary) {
				max = employee[i].salary;
				c = i;
			}
		}
		return employee[c];

	}

	// 所有的员工涨薪 ，按照百分比
	public void incrSal(double percent) {

	}
}
